package com.zyx.kafka.mq;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO
 * @Author: ZYX
 * @Date: 2022/1/4 14:59
 * @Version: 1.0
 */
@Component
public class MQListener {

    @KafkaListener(topics = {"user.register.topic"},groupId = "xdclass-gp-2")
    public void onMessage(ConsumerRecord<?, ?> record, Acknowledgment ack, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic){
        // 打印出消息内容
        System.out.println("消费："+record.topic()+"---"+record.partition()+"---"+record.value());

        ack.acknowledge();
    }

}
